package com.nursinghome.user.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.nursinghome.bean.Elderly;
import com.nursinghome.exception.NurisingHomeException;
import com.nursinghome.user.mapper.ElderlyUserMapper;
import com.nursinghome.user.service.ElderlyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ElderlyUserServiceImpl implements ElderlyUserService {
    @Autowired
    private ElderlyUserMapper elderlyUserMapper;
    //登录操作
    @Override
    public Elderly selectByeusername(String eusername, String epassword) throws NurisingHomeException {
        Elderly elderly = elderlyUserMapper.selectByeusername(eusername);
        String md5Pwd = SecureUtil.md5(SecureUtil.md5(epassword));
        if (elderly == null){
            throw new NurisingHomeException("用户名不正确");
        }

        if (!md5Pwd.equals(elderly.getEpassword())){
            throw new NurisingHomeException("密码不正确,请重新输入");
        }
        return elderly;
    }
}
